#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int t; cin >> t;
while(t--){
int n,m,k; cin >> n >> m >> k;
int a[k+1], b[k+1];
fill(a,a+k+1,0);
fill(b,b+k+1,0);
for(int i = 0; i < n; i++){
int temp; cin >> temp;
if(temp <= k){
a[temp] = 1;
}
}
for(int i = 0; i < m; i++){
int temp; cin >> temp;
if(temp <= k){
b[temp] = 1;
}
}
int ahave = 0, bhave = 0, ans = 1;
for(int i = 1; i <= k; i++){
if(a[i] == 0 and b[i] == 1){
bhave += 1;
} else if(a[i] == 1 and b[i] == 0){
ahave += 1;
} else if(a[i] == 0 and b[i] == 0){
ans = 0;
}
}
if(ahave > k/2 or bhave > k/2){
ans = 0;
}
if(ans == 0){
cout << "NO";
} else {
cout << "YES";
}
cout << "\n";
}
return 0;
}
740A - Alyona and copybooks | 1491A - K-th Largest Value |
922B - Magic Forest | 922D - Robot Vacuum Cleaner |
408B - Garland | 1391A - Suborrays |
1700C - Helping the Nature | 982A - Row |
877A - Alex and broken contest | 919D - Substring |
362B - Petya and Staircases | 1535C - Unstable String |
1738F - Connectivity Addicts | 1342B - Binary Period |
1551C - Interesting Story | 794B - Cutting Carrot |
534B - Covered Path | 1278C - Berry Jam |
1203A - Circle of Students | 1740B - Jumbo Extra Cheese 2 |
1740A - Factorise N+M | 49B - Sum |
23A - You're Given a String | 1105C - Ayoub and Lost Array |
1624E - Masha-forgetful | 998B - Cutting |
250A - Paper Work | 1740C - Bricks and Bags |
1130A - Be Positive | 465A - inc ARG |